<?php
declare (strict_types = 1);

namespace app\index\controller;

use app\common\service\AdminZavote as S;
use app\common\model\AdminZavote as M;
use app\common\model\AdminZbuserinfo as MB;
use app\common\model\AdminZccandidate as MC;
use app\common\model\AdminZdvoter as MD;
use app\common\model\AdminZitjxx as MI;
use app\common\util\Upload as Up;
use think\facade\Request;
use think\facade\Cache;
use think\Request as RQ;

class Index extends \app\BaseController
{
    /**
     * 首页
     */
    public function index()
    {
        echo "index";
        //return $this->fetch();
    }

    // 假票
    public function jp(){
        $biaoid = input('biaoid');
        $optionid = input('optionid');
        $arr = explode(',',$optionid);
        $numpiao = input('numpiao');
        S::goJp($biaoid,$arr,$numpiao);
    }

    //获取投票设置信息
    public function gettp(RQ $request)
    {
        $params = $request->params;
        if(isset($params['uid'])){
            $yonghuid = $params['uid'];
        }else{
            $yonghuid = '';
        }
        
        $id = Request::param('id');
        return json(M::gettpbyid($id,$yonghuid));
    }

    //增加点击量
    public function tpcat()
    {
        $pid = Request::param('pid');
        return json(M::tpcat($pid));
    }

    //候选增加点击量
    public function hxcat()
    {
        $zid = Request::param('zid');
        return json(MC::hxcat($zid));
    }

    //获取候选信息一
    public function gettpoptiony()
    {
        $pid = Request::param('pid');
        return json(MC::gettpoptionybypid($pid));
    }

    //前台获取候选信息一详情
    public function gettpoptionycontent()
    {
        $pid = Request::param('pid');
        return json(MC::gettpoptionycontentbypid($pid));
    }

    //前台获取候选信息二详情
    public function gettpoptione()
    {
        $pid = Request::param('pid');
        return json(MC::gettpoptionebypid($pid));
    }

    //前台获取候选信息二详情加
    public function gettpoptionejia()
    {
        $pid = Request::param('pid');
        $group = Request::param('group');
        return json(MC::gettpoptionebypidjia($pid,$group));
    }

    //前台获取候选信息二详情搜
    public function gettpoptionesou()
    {
        $pid = Request::param('pid');
        $sou = Request::param('sou');
        return json(MC::gettpoptionesoubypid($pid,$sou));
    }

    //前台获取搜
    public function gettpsou()
    {
        $pid = Request::param('pid');
        return json(MC::gettpsoubypid($pid));
    }

    //前台获取候选信息详情
    public function gettpoption()
    {
        $xiangid = Request::param('zid');
        return json(MC::gettpoptionbypid($xiangid));
    }

    //前台获取候选信息排行
    public function gettpoptionranking()
    {
        $pid = Request::param('id');
        $group = Request::param('group');
        return json(MC::gettpoptionrankingbypid($pid,$group));
    }

    //单选投票
    public function danxtp(RQ $request)
    {

        // return json(11);
        $params = $request->params;

        $biaoid = Request::param('biaoid');
        $xuanshouid = Request::param('xuanshouid');
        $zuming = Request::param('zuming');
        $wxid = Request::param('wxid');
        if(!$wxid){
            $wxid = 1;
        }
        $yonghuid = $params['uid'];
        $yonghuopenid = $params['uopenid'];
        // return json($yonghuid);
        return json(MD::danxtp($biaoid,$xuanshouid,$zuming,$wxid,$yonghuid,$yonghuopenid));
    }

    //多选投票
    public function duoxtp(RQ $request)
    {
        // return json(11);
        $params = $request->params;
        
        $biaoid = Request::param('biaoid');
        $xuanshouid = Request::param('xuanshouid');
        $zuming = Request::param('zuming');
        $yonghuid = $params['uid'];
        $yonghuopenid = $params['uopenid'];
        // return json($yonghuid);
        return json(MD::duoxtp($biaoid,$xuanshouid,$zuming,$yonghuid,$yonghuopenid));
    }

    // 前台图片上传接口
    public function uploadqtimg(){
        return json(Up::putFileqtimg(Request::file(),Request::post('path')));
    }

    // 前台视频上传接口
    public function uploadqtvideo(){
        return json(Up::putFileqtvideo(Request::file(),Request::post('path')));
    }

    // 前台音频上传接口
    public function uploadqtaudio(){
        return json(Up::putFileqtaudio(Request::file(),Request::post('path')));
    }

    // 前台文件删除接口
    public function uploadqtimgdel(){
        $path = Request::param('path');
        return json(MI::uploadqtimgdel($path));
    }

    //记录用户信息
    public function userinfo(RQ $request)
    {
        $params = $request->params;
        return json(MB::userinfo($params));
    }

    //报名获取
    public function baoming(RQ $request)
    {
        $params = $request->params;
        $utoken = $params['uid'];
        $pid = Request::param('pid');
        return json(MB::baoming($pid,$utoken));
    }

    //记录报名
    public function updatabaoming(RQ $request)
    {
        $params = $request->params;
        $biaoid = Request::param('biaoid');
        $utoken = $params['uid'];
        $data = Request::param('data');
        return json(MI::updatabaoming($biaoid,$utoken,$data));
    }

    //属性获取
    public function shuxing(RQ $request)
    {
        $params = $request->params;
        $utoken = $params['uid'];
        $pid = Request::param('pid');
        return json(MB::shuxing($pid,$utoken));
    }

    //记录属性
    public function updatashuxing(RQ $request)
    {
        $params = $request->params;
        $biaoid = Request::param('biaoid');
        $utoken = $params['uid'];
        $data = Request::param('data');
        return json(MI::updatashuxing($biaoid,$utoken,$data));
    }

    /**
     * 获得表单token
     */
    public static function getbdtk()
    {
        return json(S::goGetbdtk(Request::param()));
    }

    /**
     * 验证uToken
     */
    public static function uToken(RQ $request)
    {
        $params = $request->params;
        // $params1= $request->middleware('authData');
        // // $params['msg']='1';
        return json($params);
        // return $request->hello; // ThinkPHP
    }

    /**
     * 是否关注
     */
    public static function ywgz(RQ $request)
    {
        $yonghuopenid = $request->header('yonghuopenid');
        $voteid = $request->header('voteid');
        $votezdlgzh = $request->header('votezdlgzh');
        return json(MD::ywgz($yonghuopenid,$voteid,$votezdlgzh));
    }

}
